<?php
/**
 * Composite-Pattern zur Realisierung von Baumstrukturen
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2013 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


Class Yapary_Pattern_Composite Implements Yapary_Pattern_IComposite
{
	private $children = array();


	function __construct ( )
	{
	}


	/**
	 *
	 * */
	public function get ( )
	{
		$result = NULL;

		if (count($this->children) >= 1) {
			while (list(,$child) = each($this->children)) {
				$result .= $child->get();
			}
		}

		return $result;
	}



	public function add (Yapary_Pattern_IComposite $object)
	{
		$this->children[] = $object;
	}


	public function remove ($index)
	{
        if (!isset($this->children[$index])) {
            return false;
        }

        unset($this->children[$index]);
        return true;
	}

}

?>